let express = require('express');
let app = express();
let formidable = require('formidable');

let readFile = formidable({
    uploadDir:__dirname+'/public/upload',
    keepExtensions:true,
    maxFieldsSize:1024*1024
});


app.post('/user',(req,res)=>{

    readFile.parse(req,(err,fields,files)=>{
        if(err){
           return res.json({
                code:2001,
                msg:"图片上传失败"
            })
        }

        let {username,pwd} = fields;
        let {profile} = files;

        //获取账号密码
        console.log(`账号:${username}，密码：${pwd}`);

        //获取文件信息
        console.log(profile.newFilename);

        res.json({
            username,
            pwd,
            profile
        })

    })

});


app.listen(80,()=>{
    console.log("启动成功");
})